define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var matchId = 0;
    var Controller = {
        index: function () {
            matchId = $('#matchId').val();
            console.log(matchId+'matchId');
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'match/round/index' + location.search + '&mid='+matchId,
                    add_url: 'match/round/add?matchId=' + matchId,
                    edit_url: 'match/round/edit',
                    del_url: 'match/round/del',
                    //multi_url: 'match/round/multi',
                    //import_url: 'match/round/import',
                    table: 'match_round',
                    fixedColumns: true,
                    fixedRightNumber: 1,
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id'),visible:false},
                        {field: 'match_id', title: __('Match_id'),visible:false},
                        {field: 'match.name', title: __('Match.name'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'title', title: __('Title'), operate: 'LIKE'},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"2":__('Status 2'),"3":__('Status 3'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'create_time', title: __('Create_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,buttons:[
                            {
                                name:'成员管理',
                                extend:'data-area=["90%","90%"]',
                                title:'成员管理',
                                icon:'fa fa-btn',
                                text:'成员管理',
                                classname:'btn btn-info btn-dialog',
                                url:function(row){
                                    return '/match/roundmember/index?round_id='+row.id+'&mid='+row.match_id;
                                },
                                refresh:true
                            },
                            {
                                    name:'开始',
                                    title:'开始',
                                    text:'开始',
                                    icon:'fa fa-btn',
                                    confirm: '确定执行此操作吗?',
                                    classname:'btn btn-info btn-ajax',
                                    url:'match/round/start',
                                    refresh:true,
                                    disable:function (row) {
                                        if (row.status == 1){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name:'结束',
                                    title:'结束',
                                    icon:'fa fa-btn',
                                    text:'结束',
                                    confirm: '确定执行此操作吗?',
                                    classname:'btn btn-primary btn-ajax',
                                    url:'match/round/end',
                                    refresh:true,
                                    disable:function (row) {
                                        if (row.status == 4){
                                            return true;
                                        }
                                    }
                                },
                                {
                                    name:'撤销',
                                    title:'撤销',
                                    icon:'fa fa-btn',
                                    text:'撤销',
                                    confirm: '确定执行此操作吗?',
                                    classname:'btn btn-danger btn-ajax',
                                    url:'match/round/back',
                                    refresh:true
                                },
                                {
                                    name:'组队',
                                    title:'组队',
                                    icon:'fa fa-btn',
                                    text:'组队',
                                    confirm: '确定执行此操作吗?',
                                    classname:'btn btn-info btn-ajax',
                                    url:'match/round/generate',
                                    refresh:true
                                }
                            ]
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
